﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace PeertoPeerObjectShare.PacketHandler
{
  

    public class PackageHandler
    {

        public string packtype { get; set; }
        public string destaddr {get; set;}
        public string fromaddr{ get; set;}
        public string message { get; set; }

        public PackageHandler(string dest, string frm, string msg)
        {
            packtype = "HANDLER";
            destaddr = dest;
            fromaddr = frm;
            message = msg;
        }

        public PackageHandler()
        {
            destaddr = "blank";
            fromaddr = "blank";
            message = "blank";

        }


        public virtual string Create()
        {
            return message;

        }

        public virtual void Reset()
        {
            message = "";
        }

        public virtual string toJSON()
        {
            string json;
            try
            {
                json = JsonConvert.SerializeObject(this);
                return json;
            }
            catch (JsonSerializationException exception)
            {

                Console.WriteLine(exception.Message, "JSON CHATPACKAGE Serialization Failed");
            }
            return string.Empty;

        }


    }
}
